package io.github.wanggit.antcms.server.web;

import io.github.wanggit.antcms.server.service.ArticleService;
import io.github.wanggit.antcms.server.web.vm.ArticleVM;
import io.github.wanggit.antcms.server.web.vm.ListArticlesVM;
import io.github.wanggit.antcms.server.web.vm.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("article")
public class ArticleController {

    @Autowired private ArticleService articleService;

    @PostMapping("list")
    public Result listArticles(@RequestBody ListArticlesVM listArticlesVM) {
        return articleService.listArticles(listArticlesVM);
    }

    /**
     * 未发布状态下查看详情
     *
     * @param id
     * @return
     */
    @GetMapping("detail")
    public Result detailArticle(@RequestParam("id") Long id) {
        return articleService.detailArticle(id);
    }

    @PostMapping("save")
    public Result saveArticle(@RequestBody ArticleVM articleVM) {
        return articleService.saveArticle(articleVM);
    }

    @GetMapping("publish")
    public Result publishArticle(@RequestParam("id") Long id) {
        return articleService.publishArticle(id);
    }

    @GetMapping("qalut")
    public Result queryAllLastUpdateTime() {
        return articleService.queryAllLastUpdateTime();
    }

    @GetMapping("unpublish")
    public Result unpublishArticle(@RequestParam("id") Long id) {
        return articleService.unpublishArticle(id);
    }

    @GetMapping("trash")
    public Result trashArticle(@RequestParam("id") Long id) {
        return articleService.trashArticle(id);
    }

    @GetMapping("untrash")
    public Result untrashArticle(@RequestParam("id") Long id) {
        return articleService.untrashArticle(id);
    }

    @GetMapping("fdel")
    public Result forceDeleteArticle(@RequestParam("id") Long id) {
        return articleService.forceDeleteArticle(id);
    }
}
